<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require DOCMENT_ROOT."./Framework/model.class.php";
class usermodel extends model{
    
    public function __construct() {
        parent::connectMysqlDB("user");
        
    }
    public function chenkField($where){
        
        if($where == ""){
            return false;     
        }
        $sql = "select * from user where($where)";
        
        $arr= $this->mysql->select($sql);
        
        if($arr==null){
            return true;
        }else{
            return false;
        }
    }
        public function userList($order="id asc",$num=2,$start=0){
        $sql = "select * from user order by $order limit $start,$num";//拼接sql语句
        $arr = $this->mysqldb->select($sql);//查询
        return $arr;//返回结果
    }
        public function userCount(){
        $sql = "select count(*) as num from user";
        $arr = $this->mysqldb->select($sql);
        $count = 0;
        if(!empty($arr)) {
            $count = $arr[0]["num"];
        }
        return $count;
        
}
          public function userList2($order="id asc",$num=2,$start=0){
        $sql = "select * from xq order by $order limit $start,$num";//拼接sql语句
        $arr = $this->mysqldb->select($sql);//查询
        return $arr;//返回结果
    }
        public function userCount2(){
        $sql = "select count(*) as num from xq";
        $arr = $this->mysqldb->select($sql);
        $count = 0;
        if(!empty($arr)) {
            $count = $arr[0]["num"];
        }
        return $count;
        
}
    public function select($id){
        $sql = "select * FROM user WHERE id = $id";
        $arr = $this->mysql->selectupdate($sql);
        return $arr;
    }
    public function addUser($name,$pwd,$nick_name,$email,$tel){
        $pwd=md5($pwd);
        $sql = "insert into user(name,pwd,nick_name,email,tel)values('$name','$pwd','$nick_name','$email','$tel')";
        $rusult=$this->mysql->insert($sql);
        return $rusult;
    }
    public function addUser1($id,$title,$content,$add_time,$click){
        $sql = "insert into xq(id,title,content,add_time,click)values('$id','$title','$content','$add_time','$click')";
        $rusult=$this->mysql->insert1($sql);
        return $rusult;
    }
    
    public function update($id,$name,$pwd,$nick_name,$email,$tel){       
        $sql = "update user name= '$name',pwd = '".md5($pwd)."',nick_name='$nick_name',email='$email',tel='$tel' where id = $id";
        $arr = $this->mysql->update($sql);
        return $arr;
        
    }
    public function userUpdate($id,$pwd,$email,$tel){       
        $sql = "update user pwd = '".md5($pwd)."',email='$email',tel='$tel' where id = $id";
        $arr = $this->mysql->update1($sql);
        return $arr;
        
    }
    public function delete(){
        $sql = "DELETE FROM user WHERE id = $id";
        $arr = $this->mysql->delete($sql);
        return $arr;
    }
    public function denglu($name, $pwd){
        $pwd=md5($pwd);
        $sql = "select * from user where name='$name'and pwd='$pwd'";
//        var_dump($sql);     
        $result=$this->mysql->select1($sql);
        return $result;
    }
    
}
